/*
 * contiki_app.c
 *
 *  Created on: 2018-3-12
 *      Author: Iron
 */
#include "c_types.h"
#include "contiki.h"
#include "dhcp/dhcp.h"
#include "dhcp/dhcps.h"

//#define DHCPC_ENALBE	1
//#define DHCPS_ENALBE	1

/*---------------------------------------------------------------------------*/
void hello_world_process_init(void);
void example_abc_process_init(void);
void example_neighbors_process_init(void);
void example_mesh_process_init(void);
void udp_server_test_start(void);
void udp_client_test_start(void);

/*---------------------------------------------------------------------------*/
void dhcp_test(int gateway)
{
#if NETSTACK_CONF_WITH_IPV4
	if(!gateway){
		os_printf("dhcpc init\n");
		dhcpc_process_init();
	}else{
		#define DHCPS_LEASES_NUM	10
		int i;
		static struct dhcps_client_lease dhcps_leases[10];
		struct dhcps_config conf;

		os_printf("dhcps init\n");
		for(i=0; i<DHCPS_LEASES_NUM; i++){
			os_bzero(&dhcps_leases[i], sizeof(struct dhcps_client_lease));
		}

		os_memset(&conf, 0, sizeof(conf));
		conf.default_lease_time = (60*60); // 1 hour
		conf.flags = DHCP_CONF_NETMASK | DHCP_CONF_DNSADDR | DHCP_CONF_DEFAULT_ROUTER;
		conf.leases = dhcps_leases;
		conf.num_leases = DHCPS_LEASES_NUM;
		uip_gethostaddr(&conf.default_router);
		uip_gethostaddr(&conf.dnsaddr);
		uip_getnetmask(&conf.netmask);

		dhcps_init(&conf);
	}
#endif
}

/*---------------------------------------------------------------------------*/
void ICACHE_FLASH_ATTR
contiki_app_start(int gateway)
{
	hello_world_process_init();
//	example_abc_process_init();
//	example_neighbors_process_init();
//	example_mesh_process_init();
	udp_server_test_start();
	udp_client_test_start();

//	dhcp_test(gateway);
}
